$(function () {



    $('#SfirstDate2').datetimepicker({
        //viewMode: 'day',
        format: 'YYYY-MM-DD'
    });
    $('#SfirstDate').datetimepicker({
        format: 'YYYY-MM-DD',
        useCurrent: false //Important! See issue #1075
    });



    $('#firstDate').datetimepicker({
        //viewMode: 'day',
        format: 'YYYY-MM-DD'
    });
    $('#firstDate2').datetimepicker({
        format: 'YYYY-MM-DD',
        useCurrent: false //Important! See issue #1075
    });
    $("#firstDate").on("dp.change", function (e) {
        $('#firstDate2').data("DateTimePicker").minDate(e.date);
    });
    $("#firstDate2").on("dp.change", function (e) {
        $('#firstDate').data("DateTimePicker").maxDate(e.date);
    });




    $('#shijianyi').datetimepicker({
        //viewMode: 'day',
        format: 'YYYY-MM-DD'
    });
    $('#shijianer').datetimepicker({
        format: 'YYYY-MM-DD',
        useCurrent: false //Important! See issue #1075
    });
    $("#shijianyi").on("dp.change", function (e) {
        $('#shijianer').data("DateTimePicker").minDate(e.date);
    });
    $("#shijianer").on("dp.change", function (e) {
        $('#shijianyi').data("DateTimePicker").maxDate(e.date);
    });

    $('#table').bootstrapTable({
        url: '${pageContext.request.contextPath}/../../jianyi/quanbujianyi',
        columns: [{
            field: '0',
            title: 'id',
            visible : false,
        },{
            field: '1',
            title: '单据编号'
        },{
            field: '2',
            title: '业主门牌号'
        },{
            field: '3',
            title: '建议时间'
        },{
            field: '4',
            title: '接待员工'
        },{
            field: '5',
            title: '建议，意见内容'
        }, {
            field : '7',
            title : '内容类型'
        },{
            field:'6',
            title:'受理状态',
            formatter:function (value,row,index) {
                if (row[6]==1){
                    return "已受理";
                }else if(row[6]==2) {
                    return "未受理";

                }
            }


        },{
            field:'8',
            title:'受理时间'
        }, {
            field : 'xx',
            title : '操作',


            formatter:function(value,row,index){

                return "<a href='javascript:del("+row[0]+")'>删除</a>" ;
            }
        }],
        contentType : "application/x-www-form-urlencoded",
        queryParamsType:'',
        queryParams: queryParams,
        height:680,
        pageList:[1,10,15],
        pageNumber:1,
        pageSize:15,
        pagination:true,
        sidePagination:'server',

        onDblClickRow: function (row, $element, field) {
            $("#myModal2").modal("show");
            $("#Sorder").val(row[1]);
            $("#Smenpai").val(row[2])
            $("#SfirstDate").val(row[3])
            $("#Sjiedaiyuangong").val(row[4])
            $("#Sjianyineirong").val(row[5])
            $("#Sjleixing").val(row[6])
            $("#SfirstDate2").val(row[8])
            $("#Sshoulizhuangtai").val(row[7])
            $("#yin1").val(row[0]);


        },
    });
})



//增加数据
function add2() {
    var opt = $("#table").bootstrapTable('getOptions');
    //单据编号
    var order = $("#order").val();
    //门牌号
    var num = $("#menpai").val();
    //建议时间
    var date = $("#firstDate").val();
    //接待员工
    var yuangong=$("#jiedaiyuangong").val();
    //建议内容
    var neirong = $("#jianyineirong").val();
    //内容类型
    var contenttype=$("#leixing").val();
   //受理时间
    var shoulishijian=$("#firstDate2").val();
    //受理状态
    var zhuangtai=$("#shoulizhuangtai").val();
        $.post("${pageContext.request.contextPath}/../../jianyi/Qtianjia",{"order":order,"num":num,"date":date,"yuangong":yuangong,"neirong":neirong,"contenttype":contenttype,"shoulishijian":shoulishijian,"zhuangtai":zhuangtai,"pageNumber":opt.pageNumber,"pageSize":opt.pageSize},function (data) {
            $("#table").bootstrapTable("load",data);
    })
}

//修改数据
function upd() {
    var opt = $("#table").bootstrapTable('getOptions');
    //单据编号
    var order = $("#Sorder").val();

    //门牌号
    var num = $("#Smenpai").val();
    //建议时间
    var date = $("#SfirstDate").val();
    //接待员工
    var yuangong=$("#Sjiedaiyuangong").val();
    //建议内容S
    var neirong = $("#Sjianyineirong").val();
    //内容类型
    var contenttype=$("#Sjleixing").val();
    //受理时间
    var shoulishijian=$("#SfirstDate2").val();
    //受理状态
    var zhuangtai=$("#Sshoulizhuangtai").val();
    var yin1 = $("#yin1").val();
    $.post("${pageContext.request.contextPath}/../../jianyi/Qxiugai",{"id":yin1,"order":order,"num":num, "date":date,"neirong":neirong,"contenttype":contenttype,"yuangong":yuangong,"shoulishijian":shoulishijian,"zhuangtai":zhuangtai,"pageNumber":opt.pageNumber,"pageSize":opt.pageSize},function (data) {
        $("#table").bootstrapTable("load",data);
    })
}

//按条件查询
function ban(){
    var opt = $("#table").bootstrapTable('getOptions') ;
    var firstDate = $("#shijianer").val() ;
    var secondDate = $("#shijianyi").val() ;
    var zhuangtai = $('#zhuangtai').val();

    $.post('${pageContext.request.contextPath}/../../jianyi/quanbujianyi',{'zhuangtai':zhuangtai,'pageNumber':opt.pageNumber,'pageSize':opt.pageSize,'firstDate':firstDate,'secondDate':secondDate},function(data){
        //重新给table绑定数据5
        $("#table").bootstrapTable("load",data) ;
    });
}
function queryParams(params) {
    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
        'pageSize': params.pageSize,  //页面大小
        'pageNumber': params.pageNumber, //页码
        'secondDate':$("#shijianyi").val(),
        'firstDate':$("#shijianer").val(),
        'zhuangtai': $("#zhuangtai").val(),
    };
    return temp;
};



//删除数据
function del(id) {
    var id=id;
    var opt = $("#table").bootstrapTable('getOptions') ;
    $.post("${pageContext.request.contextPath}/../../jianyi/Qdel",{"id":id,"pageNumber":opt.pageNumber,'pageSize':opt.pageSize},function (data) {
        $("#table").bootstrapTable("load",data);
    })
}






